package com.xbongbong.paas.handle;

import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.weblist.pojo.ListOptionPackagePojo;
import com.xbongbong.saas.help.SaasListHelp;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author mingliang
 * @Description
 * @Date 2021/11/27 17:16
 **/
@Component
public class SalesOpportunityOptionHandle extends AbstractOptionHandle {

    @Resource
    private SaasListHelp saasListHelp;

    @Override
    public void setOptionsInExplain(FormDataListDTO formDataListDTO, List<FieldAttrEntity> explainList, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException {
        String corpid = formDataListDTO.getCorpid();
        // 获取按钮的开关
        ListOptionPackagePojo listOptionPackagePojo = getListOption(formDataListDTO);

        // 拼装表头
        saasListHelp.setHeadList(explainList, listOptionPackagePojo, formDataListDTO.getSubBusinessType(), formDataListDTO.getBusinessType());
        // 去掉子表单标题头，实际上可以加在HandleExplainHelp.handleExplain中，但是避免对其他业务造成影响，先写在这里，如果全部列表改造的话，可统一改到HandleExplainHelp.handleExplain中
        removeSubFormItems(explainList, formDataListDTO.getBusinessType());
    }

    @Override
    public void setOptionsInData(FormDataListDTO formDataListDTO, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException {
        setOptions(formDataListDTO, paasFormDataEsListVO, getListOption(formDataListDTO));
    }

    @Override
    public ListOptionPackagePojo getFirstOptionData(FormDataListDTO formDataListDTO, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException {
        return null;
    }

    private ListOptionPackagePojo getListOption(FormDataListDTO formDataListDTO){
        ListOptionPackagePojo listOptionPackagePojo = new ListOptionPackagePojo();
        //提醒
        listOptionPackagePojo.setNeedOption1(true);
        listOptionPackagePojo.setNeedOption2(true);
        saasListHelp.getPushNotify(formDataListDTO.getIdIn(), formDataListDTO.getCorpid(), formDataListDTO.getBusinessType(), listOptionPackagePojo.getPushNotifyList());

        return listOptionPackagePojo;
    }
}